package com.hubt.controller;

import org.apache.ibatis.annotations.Param;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hubt.common.PageBean;
import com.hubt.model.PtMenuDirectory;
import com.hubt.model.Res;
import com.hubt.model.ResTree;
import com.hubt.service.PtMenuDirectoryService;
import com.hubt.vo.Resvo;





@Controller
@RequestMapping("/res")
public class PtMenuDirectoryController {
	@Autowired
	private PtMenuDirectoryService ptservice;
	
	@ResponseBody
	@RequestMapping(value = "/getResources",method = RequestMethod.GET)
	public PageBean<Resvo> teString(@Param("pageSize") Integer pageSize,@Param("pageNumber") Integer pageNumber) {
		System.out.println(pageNumber);
		System.out.println(pageSize);
		PageBean<Resvo> resources =new PageBean<Resvo>();
		resources=ptservice.findRes(pageNumber,pageSize);
		System.out.println(resources.getTotal());
		System.out.println(resources.getRows().size());
		return resources;
	}
	
	@RequestMapping(value = "insert",method=RequestMethod.POST)
	@ResponseBody
	public boolean Insert(@Param("form") Res res) {
		System.out.println(res);
		return ptservice.insert(res);
//		return true;
	}
	
	
	
	@RequestMapping(value = "/update",method=RequestMethod.POST)
	@ResponseBody
	public boolean Update(@Param("form") Res res) {
		return ptservice.update(res);
	}
	
	@RequestMapping(value = "/remove",method=RequestMethod.GET)
	@ResponseBody
	public boolean delete(@Param("id") String id) {
		return ptservice.delete(id);
	}
	
	
	@RequestMapping(value = "/getResourcesByParentId",method = RequestMethod.GET)
	@ResponseBody
	public ResTree treeList(@Param("parentId") String parentId) {
		System.out.println(parentId);
		ResTree resTree=new ResTree();
		resTree=ptservice.resTree(parentId);
		return resTree;
	}
	
	@RequestMapping(value = "/getResource",method = RequestMethod.GET)
	@ResponseBody
	public Res reslist(@Param("uuid") String uuid) {
		Res res=new Res();
		return ptservice.getRes(uuid);
	}
	
	
}
